<?php

	$uuid = $_REQUEST['UUID'];
	$userId = $_REQUEST['UserId'];
	$signature = $_REQUEST['Signature'];
	$latitude = $_REQUEST['Latitude'];
	$longitude = $_REQUEST['Longitude'];
	$address = $_REQUEST['Address'];
	$hasImage = $_REQUEST['HasImage'];
	if($hasImage == 'TRUE')
	{
		$hasImage = 1;
	}
	else 
	{
		$hasImage = 0;
	}
	$time = date("Y-m-d H:i:s");
	//－－－  连接服务器  －－－
	$con = mysql_connect("127.0.0.1:3306","root","1qazse4");
	$DataName = 'ShareNavigation';
	if(!$con)
	{
		die('无法连接远程服务器: '.mysql_error);
	}
	//－－－  链接指定数据库  －－－
	mysql_query("SET NAMES UTF8");
	mysql_select_db($DataName,$con);
	//echo $_FILES["image"]["type"];
	//有图片的情况下
	if($hasImage == 1)
	{
			 if((($_FILES["image"]["type"] == "image/png")
       		|| ($_FILES["image"]["type"] == "image/jpeg")
	   		|| ($_FILES["image"]["type"] == "image/jpg"))
       		)
    	{
    
        	if($_FILES["image"]["error"] > 0)
        	{
        		//---  输出错误信息  ---
            	echo "Error: " . $_FILES["image"]["error"];
        	}
        	else
        	{
        		/*
            	echo "Upload: " . $_FILES["image"]["name"]
            	. "<br />";
           	 	echo "Type: " . $_FILES["image"]["type"]
           	 	. "<br />";
        	    echo "Size: " . ($_Files["image"]["size"]/1024)
        	    . " Kb<br />";
    	        echo "Stored in: " . $_FILES["image"]["tmp_name"];
   	         */
   	         /*
        	    $str = "upload/" . $_FILES["file"]["name"];
    	        echo "<br /><br />test" . file_exists($str);
   	         */
           		// echo "<br />upload/" . $_FILES["image"]["name"];
             	if(file_exists("upload/" . $_FILES["image"]["name"]))
            	{
        	        echo  '请不要重复签到';
      	    	}
            	else
           		 {
            	    move_uploaded_file($_FILES["image"]["tmp_name"],
        	        "upload/" . $_FILES["image"]["name"]);
					//echo $longitude . "   " . $latitude . "   " .$hasImage;	
					$query = "INSERT INTO UserTravel 
						(UUID, UserID,Location,Time,TravelSignature,Longitude,Latitude,HasImage) 
						VALUES (\"$uuid\",\"$userId\",\"$address\",\"$time\",\"$signature\"
						,'$longitude','$latitude','$hasImage')";
					if (!mysql_query($query,$con))
  					{
  						//echo "AccountNumber". '<br />';
  						//---  如果数据库插入语句出错，就把已上传文件给删除   ---
  						$file = "upload/" . $_FILES["image"]["name"];
						unlink($file);
 						die('服务器错误: ' . mysql_error());
 					}
					else
					{
						echo 'TRUE';
					}
            	   // echo "Stored in: ". "upload/" . $_FILES["file"]["name"];
        	    }
    	    }
   		 }
    	else
    	{
        	echo "不正确的文件";
   	 	}
	}
	//---  没有图片的情况下   --- 
	else
 	{
 		$query = "INSERT INTO UserTravel 
			(UUID, UserID,Location,Time,TravelSignature,Longitude,Latitude,HasImage) 
			VALUES (\"$uuid\",\"$userId\",\"$address\",\"$time\",\"$signature\"
			,'$longitude','$latitude','$hasImage')";
		if (!mysql_query($query,$con))
  		{
 			die('服务器错误: ' . mysql_error());
 		}
		else
		{
			echo 'TRUE';
		}
 	}

	mysql_close($con);
   
?>